library(effects)
library(tidyverse)
library(stargazer)
library(gridExtra)
library(scales)
setwd("~/Dropbox/projects/inseparability/replication")
dr <- read_csv("pre-test.csv")

dr <- dr[dr$gc ==1,]
d <- dr %>% gather(dose, response, c("f1", "f2", "f3", "f4"))
d$amount  <-NA
d$amount[d$dose == "f1"] <- d$round1.amount[d$dose == "f1"]
d$amount[d$dose == "f2"] <- d$round2.amount[d$dose == "f2"]
d$amount[d$dose == "f3"] <- d$round3.amount[d$dose == "f3"]
d$amount[d$dose == "f4"] <- d$round4.amount[d$dose == "f4"]
table(d$response)
d$response2[d$response=="Very unfairly"] <- 1
d$response2[d$response=="Unfairly"] <- 2
d$response2[d$response=="Fairly"] <- 3
d$response2[d$response=="Very fairly"] <- 4
str(d$response)
ggplot(d, aes(x=amount, y=response2)) + 
	geom_smooth() +
	ylim(1,4)


d <- dr %>% gather(dose, response, c("t1", "t2", "t3", "t4"))
d$amount  <-NA
d$amount[d$dose == "t1"] <- d$round1.amount[d$dose == "t1"]
d$amount[d$dose == "t2"] <- d$round2.amount[d$dose == "t2"]
d$amount[d$dose == "t3"] <- d$round3.amount[d$dose == "t3"]
d$amount[d$dose == "t4"] <- d$round4.amount[d$dose == "t4"]

d$response2[d$response=="Definitely yes"] <- 5
d$response2[d$response=="Probably yes"] <- 4
d$response2[d$response=="Might or might not"] <- 3
d$response2[d$response=="Probably no"] <- 2
d$response2[d$response=="Definitely no"] <- 1


trust <- ggplot(d, aes(x=amount, y=response2)) + 
	geom_smooth() +
	geom_hline(yintercept = 4) + 
	ylab("Assessed Trust") + 
	xlab("Allocation") + 
	theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
		  panel.background = element_blank(), axis.line = element_line(colour = "black")) + 
	scale_x_continuous(label=dollar_format(), breaks=c(0:10)) +
	ggtitle("") +
	coord_cartesian(ylim=c(3,5))


ggsave(plot=trust, "dose_response.pdf", width=4, height=4)
